package com.heima.article.controller;

import com.heima.article.entity.ApArticle;
import com.heima.article.entity.ApAuthor;
import com.heima.article.service.IApArticleService;
import com.heima.article.service.IApAuthorService;
import com.heima.common.dto.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * APP文章作者信息表 前端控制器
 * </p>
 *
 * @author wsj
 * @since 2022-03-11
 */
@RestController
@RequestMapping("/api/v1/author")
@Api(tags = "APP文章作者信息表接口")
public class ApAuthorController{

    @Autowired
    private IApAuthorService apAuthorService;

    /**
     * 新增文章作者
     * @param apAuthor
     * @return
     */
    @ApiOperation(value = "新增文章作者",notes = "author:wsj")
    @ApiImplicitParam(name = "apAuthor",value = "文章作者参数",required = true,dataType = "ApAuthor")
    @PostMapping
    public ResponseResult<ApAuthor> save(@RequestBody ApAuthor apAuthor) {
        return apAuthorService.saveApAuthor(apAuthor);
    }
    @ApiOperation(value = "查询文章作者",notes = "author:wsj")
    @ApiImplicitParam(name = "id",value = "文章id",required = true,dataType = "Integer")
    @GetMapping("/{id}")
    public ResponseResult<ApAuthor> findById(@PathVariable("id") Integer id) {
        ApAuthor apAuthor = apAuthorService.getById(id);
        return ResponseResult.okResult(apAuthor);
    }
    @Autowired
    private IApArticleService apArticleService;
    @PutMapping("/find")
    public ResponseResult<ApAuthor> find(@RequestBody Long id){
        ApArticle apArticle = apArticleService.getById(id);
        ApAuthor author = apAuthorService.getById(apArticle.getAuthorId());
        return ResponseResult.okResult(author);
    }
}
